package cn.zh.npro.citythreelist;

import android.content.Intent;
import android.os.Bundle;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import cn.zh.npro.Activity.BaseActivity;
import cn.zh.npro.Item.CityInfoBean;
import cn.zh.npro.Item.CityTem;
import cn.zh.npro.MyApplication;
import cn.zh.npro.R;
import cn.zh.npro.Util.CityListLoader;

import static cn.zh.npro.Util.CityListLoader.BUNDATA;


public class ProvinceActivity extends BaseActivity {
    
    private TextView mCityNameTv;
    
    private RecyclerView mCityRecyclerView;

    MyApplication mapp;
    ImageView img_left;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_citylist);
        mapp= (MyApplication) getApplication();
        initView();
        setData();
       }
    
    private void setData() {
        
        final List<CityInfoBean> cityList = CityListLoader.getInstance().getProListData();
        if (cityList == null) {
            return;
         }
        
        CityAdapter cityAdapter = new CityAdapter(ProvinceActivity.this, cityList);
        mCityRecyclerView.setAdapter(cityAdapter);
        cityAdapter.setOnItemClickListener(new CityAdapter.OnItemSelectedListener() {
            @Override
            public void onItemSelected(View view, int position) {
                CityTem cityTem=new CityTem(cityList.get(position).getName(),cityList.get(position).getId());
                mapp.setProviece(cityTem);
                Intent intent = new Intent(ProvinceActivity.this, CityActivity.class);
                intent.putExtra(BUNDATA, cityList.get(position));
                startActivity(intent);
                  }
              });
            }
    
    private void initView() {
        mCityNameTv = (TextView) findViewById(R.id.cityname_tv);
        img_left= (ImageView) findViewById(R.id.img_left);
        mCityNameTv.setText("选择省份");
        mCityRecyclerView = findViewById(R.id.city_recyclerview);
        mCityRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mCityRecyclerView.addItemDecoration(new RecycleViewDividerForList(this, LinearLayoutManager.HORIZONTAL, true));
        img_left.setOnClickListener(this);
    }


    @Override
    public void onClick(View view) {
        super.onClick(view);
        int id=view.getId();
        switch (id){
            case R.id.img_left:
                finish();
                break;
        }
    }
}
